Skip to content

feat: add xmodem cp upload/download command#915

Draft
benallfree wants to merge 9 commits into
meshtastic:masterfrom
MeshEnvy:feat/xmodem-cp
Draft

feat: add xmodem cp upload/download command#915
benallfree wants to merge 9 commits into
meshtastic:masterfrom
MeshEnvy:feat/xmodem-cp

Conversation

@benallfree
Copy link
Copy Markdown

@benallfree benallfree commented Apr 13, 2026

This PR adds support for Meshtastic's XMODEM-based file copy feature.

Prerequisites:

@benallfree benallfree marked this pull request as ready for review April 13, 2026 00:11
@benallfree benallfree mentioned this pull request Apr 13, 2026
@benallfree benallfree marked this pull request as draft April 13, 2026 23:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds XMODEM-based file transfer support to the Meshtastic Python library and CLI, enabling device-side file upload/download plus directory listing and download planning for trees/globs.

Changes:

  • Added XMODEM transfer helpers to Node (uploadFile, downloadFile, listDir) plus CRC16 support.
  • Added CLI planning utilities for uploads/downloads (including local globs and remote tree/glob planning).
  • Wired new CLI flags (--upload, --download, --download-tree, --download-glob, --ls) and added unit tests for the new functionality.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
meshtastic/node.py Implements XMODEM send/receive logic, CRC16, and Node-level upload/download/listDir APIs.
meshtastic/file_transfer_cli.py Adds reusable path/glob planning helpers for CLI-driven multi-file transfers.
meshtastic/main.py Adds CLI arguments and integrates the new transfer operations into the CLI workflow.
meshtastic/tests/test_node.py Adds unit tests covering XMODEM CRC, upload/download flows, and MFLIST parsing behavior.
meshtastic/tests/test_file_transfer_cli.py Adds unit tests for upload/download planning helpers (globs, tree/glob selection).

Comment thread meshtastic/node.py
return False

try:
data = open(local_path, "rb").read()
Comment thread meshtastic/node.py
Comment on lines +1159 to +1164

# SOH seq=0 — filename handshake
xm = xmodem_pb2.XModem()
xm.control = XC.SOH
xm.seq = 0
xm.buffer = device_path.encode("utf-8")[: self._XMODEM_BUFFER_MAX]
Comment thread meshtastic/node.py
Comment on lines +1113 to +1116
def _on_xmodem(packet, interface):
result[0] = packet
event.set()

Comment thread meshtastic/node.py
Comment on lines +1264 to +1267
xm = xmodem_pb2.XModem()
xm.control = XC.STX
xm.seq = 0
xm.buffer = device_path.encode("utf-8")[: self._XMODEM_BUFFER_MAX]
Comment thread meshtastic/node.py
Comment on lines +1269 to +1270
chunks: list = []
expected_seq = 1
if sz <= 0:
continue
path = path.replace("\\", "/")
if not path.startswith(remote_dir):
Comment on lines +231 to +236
tail = path[len(remote_dir) :].lstrip("/")
if not tail:
continue
local_path = os.path.join(local_root, *tail.split("/"))
out.append((path, os.path.normpath(local_path)))

Comment on lines +264 to +271
rel = path[len(base_n) :].lstrip("/")
if not rel:
continue
if not rx.match(rel):
continue
local_path = os.path.join(local_root, *rel.split("/"))
out.append((path, os.path.normpath(local_path)))

Comment on lines +1 to +10
"""Tests for meshtastic.file_transfer_cli."""

import os
import tempfile

import pytest

from meshtastic.file_transfer_cli import (
FileTransferCliError,
XMODEM_DEVICE_PATH_UTF8_MAX,
Comment thread meshtastic/node.py
Comment on lines +1225 to +1228
def _cb(packet, interface):
result[0] = packet
event.set()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants